import Vue from 'vue'
import VueRouter from 'vue-router'
import Home from '../views/home/Home.vue'
import Login from '../views/my/Login'
import Register from '../views/my/Register'
import Blog from '../views/blog/Blog'
import MyBlog from '../views/my/MyBlog'
import Active from '../views/my/Active'
import Community from '../views/community/Community'
import File from '../views/file/File'
import PrivateFile from "../views/file/PrivateFile";
import PublickFile from "../views/file/PublicFile";
import Upload from "../views/file/Upload";
import CreateBlog from "../views/my/CreateBlog";
import My from "../views/my/My";
import Detail from "../views/community/detail/Detail";
import Face from "../views/my/Face";
import Face2 from "../views/my/Face2";
import Website from "../views/website/Website";

Vue.use(VueRouter)

const routes = [
  {
    path: '/home',
    name: 'Home',
    component: Home,
  },
  {
    path: '/face',
    name: 'Face',
    component: Face,
  },
  {
    path: '/face2',
    name: 'Face2',
    component: Face2,
  },
  {
    path: '/myblog',
    name: 'MyBlog',
    component: MyBlog,
    meta: { title: '我的博客' }
  },
  {
    path: '/blog',
    name: 'Blog',
    component: Blog,
    meta: { title: '博客待定' }
  },
  {
    path: '/community',
    name: 'Community',
    component: Community,
    meta: { title: '社区' },
    children: [
      {
        path: 'detail',
        component: Detail,
        meta: { title: '视频详情' }
      }
    ]
  },
  {
    path: '/website',
    name: 'website',
    component: Website,
    meta: { title: '网站链接' }
  },
  {
    path: '/file',
    name: 'File',
    redirect: '/file/public',
    component: File,
    children: [{
      path: 'private',
      component: PrivateFile
    }, {
      path: 'public',
      component: PublickFile
    }, {
      path: 'upload',
      component: Upload,
      meta: { title: '上传文件' }
    }],
    meta: { title: '文件' },
  },
  {
    path: '/login',
    name: 'Login',
    component: Login,
    meta: { title: '登录' },
  },
  {
    path: '/active',
    name: 'Active',
    component: Active,
    meta: { title: '注册校验' },
  },
  {
    path: '/register',
    name: 'register',
    component: Register,
    meta: { title: '注册' }
  },
  {
    path: '/createblog',
    name: 'createblog',
    component: CreateBlog,
    meta: { title: '创建博客' }
  },
  {
    path: '/my',
    name: 'my',
    component: My
  },
  {
    path: '/',
    redirect: '/home',
    component: Home
  }
]

const router = new VueRouter({
  routes,
  scrollBehavior () {
    return {x: 0, y: 0}
  }
})

router.beforeEach((to, from, next) => {
  if (to.meta && to.meta.title) {
    document.title = to.meta.title
  } else {
    document.title = 'MAX技术平台'
  }
  next()
})

export default router
